package com.baosight.sczx.common.zm.cInterface.cm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.sczx.zm.cm.domain.ZMCMMaterialBasicInfo;

/**
 * 物资基础信息分类
 * <p>Title: MaterialBasicInfo.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 杨鸣
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-1 下午05:20:13  杨鸣  Create
 *</pre>
 */
public class MaterialBasicInfo {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 
	 * <p>Function: delMaterialBasicInfo</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-15下午02:23:58 杨鸣
	 * </p>
	 *
	 */
//	@SuppressWarnings("unchecked")
//	public static EiInfo delMaterialBasicInfo(EiInfo inInfo,String typeInnerCode){
//		List<Map> _list = new ArrayList<Map>();
//		try {
//			Map _argMap = new HashMap();
//			_argMap.put("treeTypeInnerCode", typeInnerCode);
//			_list = dao.query("ZMCMMaterialBasicInfo.query", _argMap);
//			inInfo.getBlock(EiConstant.resultBlock).addRows(_list);
//			
//
//			for(int i=0;i<inInfo.getBlock(EiConstant.resultBlock).getRowCount();i++)
//			{
//				String fdMaterialInnerCode = inInfo.getBlock("result").getCellStr(i, "fdMaterialInnerCode");
//				//先去掉物资内码中root部分
//				String noRootMaterialInnerCode =  fdMaterialInnerCode;
//				if (fdMaterialInnerCode.startsWith("root")){
//					noRootMaterialInnerCode = fdMaterialInnerCode.substring(4,fdMaterialInnerCode.length());				
//				}
//				inInfo.getBlock("result").setCell(i, "fdMaterialInnerCode","del" + noRootMaterialInnerCode );//删除物资编码时，修改物资内码为 del +物资内码(去掉root)
//			}
//			inInfo = dao.update("ZMCMMaterialBasicInfo.update", inInfo);
//			
//		} catch (Exception e) {
//			return inInfo;
//		}
//
//		return inInfo;
//	}

	/**根据调价结果更新物资单价
	 * <p>Function updateValue</p>
	 * @param inInfo
	 * @param string
	 * @param name
	 *  <p>History:
	 *    2011-6-30 4:02:10 贾雪民
	 * </p>
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static EiInfo updateValue(EiInfo inInfo) {
		Map<String, String> _map = new HashMap<String, String>();
		_map = (HashMap)inInfo.getBlock("result").getRows().get(0);
		dao.update("ZMCMMaterialBasicInfo.updatevalue",_map ); //更新单价
		return inInfo;
	}
	
	/**
	 * 编辑物资模块 获取物资记录
	 * <p>Function: getMaterialInfo</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-03-08上午08:39:20 高强
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static EiInfo getMaterialInfo(EiInfo inInfo){                    	
		try {
			List<Map>  _list = new ArrayList();
			Map para = new HashMap();
			para.put("fdMaterialName", inInfo.getBlock("inqu_status").getCellStr(0, "fdMaterialName"));
			para.put("fdMaterialCode", inInfo.getBlock("inqu_status").getCellStr(0, "fdMaterialCode"));
			para.put("fdTypeCode", inInfo.getBlock("inqu_status").getCellStr(0, "fdTypeCode"));
		    _list = dao.query("ZMCMMaterialBasicInfo.query", para);
			inInfo.addBlock(EiConstant.resultBlock).addBlockMeta(new ZMCMMaterialBasicInfo().eiMetadata);
			inInfo.getBlock(EiConstant.resultBlock).addRows(_list);

		} catch (Exception e) {
			return inInfo;
		}
		return inInfo;
	}

}
